<h1>用户登录</h1>

<div class="row">
  <div class="col-sm-4">
    <%= form_tag sessions_path, method: "post", remote: true, class: "signin_form" do %>
      <div class="form-group">
        <%= text_field_tag :username, nil, class: "form-control", placeholder: "用户名..." %>
      </div>
      <div class="form-group">
        <%= password_field_tag :password, nil, class: "form-control", placeholder: "密码..." %>
      </div>
      <%= submit_tag "登录", class: "btn btn-primary" %>
      <%= link_to "注册", new_user_path %>
    <% end %>
  </div>
  <div class="col-sm-8">
  </div>
</div>

<%= content_for :javascripts do %>
  <script type="text/javascript">
    $('.signin_form').on('ajax:success', function(event, data) {
      if (data.status == 'ok') {
        window.location.href = data.msg.redirect_url;
      } else {
        alert(data.msg);
      }
    })
  </script>
<% end -%>